---
title: Render an SSRS report
summary: Loads, parameterizes, and renders an SSRS catalog report to the caller-selected format under the hosting process's Windows identity.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-09-01
library: SAIF.Services.Printing
reference_type: embedded
operation_id: op-12-render-an-ssrs-report
trigger: clsRSPrint.PreviewDocument invoked
---

# Render an SSRS report

Loads an SSRS catalog report, applies any accumulated parameters, and renders it to the format selected via `Format`, returning the rendered bytes. Execution always runs under the hosting process's default Windows credentials rather than any caller-supplied identity.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-12 |
| **Trigger** | `clsRSPrint.PreviewDocument` invoked |
| **Inputs** | `ReportPath`, `Format` (enum-driven), accumulated parameters via `AddParameter` |
| **Outputs** | Rendered bytes (`Byte()`) |
| **Primary components** | `clsRSPrint.PreviewDocument`, `clsRSPrint.Format` setter, `BuildParameters`, `SharepointReporting.ReportExecutionService` |
| **Entry point** | `Public Function PreviewDocument() As Byte()` |

## Steps

1. Caller sets `Format` (a `Formats` enum) before calling `PreviewDocument`; the setter maps the enum to both an SSRS format string (`m_Format`) and a fixed extension (`m_Extension`): CSV→csv, Excel→xls, HTML→html, Image→jpeg, PDF→pdf, Word→doc, XML→xml ([BR-PRT-011](../business-rules.md#br-prt-011-rendered-file-extension-fixed-by-format)).
2. `PreviewDocument()` sets `m_RS.Credentials = System.Net.CredentialCache.DefaultCredentials`, so the SSRS call executes under the hosting process's Windows identity rather than any caller-supplied credential ([BR-PRT-020](../business-rules.md#br-prt-020-ssrs-execution-under-hosting-process-identity)).
3. Calls `m_RS.LoadReport2(ReportPath, HistoryID)`, deliberately passing a `HistoryID` local variable that is never initialized before the call — the code contains an explicit comment warning that initializing it makes the call fail with an invalid `SnapshotId`.
   - On failure: no `Try`/`Catch` surrounds this call; any `SoapException` propagates unhandled to the caller.
4. If any parameters were added via `AddParameter`: builds a `SharepointReporting.ParameterValue()` array via `BuildParameters` (one entry per accumulated name/value pair) and calls `m_RS.SetExecutionParameters(ReportParameters, Nothing)`.
   - If no parameters were added: this step is skipped entirely.
5. Calls `m_RS.Render2(m_Format, devinfo, PageCountMode.Actual, m_Extension, encoding, mimeType, Warnings, streamIDs)`, passing the format/extension pair established in step 1 so they agree ([BR-PRT-011](../business-rules.md#br-prt-011-rendered-file-extension-fixed-by-format)).
   - On failure: no `Try`/`Catch` surrounds this call either; any `SoapException` propagates unhandled to the caller.
6. Returns the rendered byte array from `Render2` directly to the caller.

## Process flow

The following diagram visualizes this operation's control flow, from format selection through the unhandled SSRS calls to the returned bytes.

```mermaid
flowchart TD
	Start(["PreviewDocument called"]) --> FormatMap["Format already set:<br>format-to-extension map"]
	FormatMap --> Creds["Set DefaultCredentials"]
	Creds --> Load["LoadReport2(ReportPath,<br>uninitialized HistoryID)"]
	Load --> ParamCheck{"Parameters added?"}
	ParamCheck -->|Yes| Build["BuildParameters,<br>SetExecutionParameters"]
	ParamCheck -->|No| Render
	Build --> Render["Render2 with format/extension"]
	Render --> End(["Return rendered bytes"])
```

## Failure and edge-case behavior
- No `Try`/`Catch` blocks exist anywhere in `PreviewDocument`; any `SoapException` raised by `LoadReport2`, `SetExecutionParameters`, or `Render2` propagates unhandled to the caller.
- `clsRSPrint.DistributeDocument` unconditionally throws `NotImplementedException` — SSRS distribution is not supported ([BR-PRT-012](../business-rules.md#br-prt-012-ssrs-distribution-not-supported)).
- The `ImageFormat` property sets `m_ImageFormat` via its own independent switch statement, but `m_ImageFormat` is never referenced anywhere in `PreviewDocument` or in the `Render2` call — only `m_Format`/`m_Extension` (driven by the separate `Format` property) are actually used. `ImageFormat` currently has no observable effect on rendering output.*
- The private, environment-service-accepting constructor (`Private Sub New(envSvc As EnvironmentServiceBase)`) is reachable only through the public parameterless `New()`, which always resolves `AppGlobal.EnvironmentService` — mirroring the `clsPrint`/`ReportBase.xPrint` environment-service propagation gap present elsewhere in this library.*

## Related documentation
- [Index](../index.md)
- [Overview](../overview.md)
- [Architecture](../architecture.md)
- [Dependencies](../dependencies.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [API reference](../api/index.md)

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- `SAIF.Services.Printing/clsRSPrint.vb`
